package com.hjr.calculator;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtil {

    private static final Pattern pattern = Pattern.compile("(^[+-]?[0-9]+)|(^[-+]?[0-9]\\.[0-9]*[1-9]$)|(^[-+]?[1-9]+[0-9]*\\.[0-9]*[1-9]$)");

    /**
     * 通过正则表达式判断字符串是否为数字
     * @param str str
     * @return boolean
     */
    public static boolean isNumber(String str) {
        Matcher m = pattern.matcher(str);
        return m.matches();
    }
}
